package team.se.tms.handle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import team.se.tms.exception.CustomException;
import team.se.tms.util.ResultUtil;

/**
 * 异常拦截器
 *
 * @author winkyle
 * @date 2018/11/15
 */
@Slf4j
@RestController
@ControllerAdvice
public class ExceptionHandle {
    /**
     * 拦截异常，并返回异常信息
     *
     * @param customException 自定义异常
     * @return 异常信息
     * @create on 2018/11/15 by winkyle
     */
    @ExceptionHandler(value = CustomException.class)
    public Object error(CustomException customException) {
        log.debug(customException.toString());
        return ResultUtil.error(customException.getCode(), customException.getMessage().toString());
    }

}
